<!--<html>-->
<fieldset>
  <div><legend>内容</legend></div>
<% if (!problem) { %>
  <div class="alert alert-error" style="padding:100px;">
    <h1 align="center">The Problem is not Available!!</h1>
  </div>
<% } else { %>
<% var submit = '<a class="uibtn checklogin" href="javascript:;" pid="'+problem.problemID+'" id="gotosubmit">Submit</a><a class="uibtn" href="/statistic/'+problem.problemID+'">Statistic</a>'; %>
  <div class="thumbnail" style="padding:1em;">
    <div id="sidebar" pid="<%= problem.problemID %>">
      <div class="sidebox">
        <div class="side-header">→ Information</div>
        <ul class="info">
          <li>
            <span>Solved Number</span>
            <a class="user-green" href="/status?pid=<%= problem.problemID %>&result=2"><%= problem.AC %></a>
          </li>
          <li>
            <span>Submit Number</span>
            <a class="user-green" href="/status?pid=<%= problem.problemID %>"><%= problem.submit %></a>
          </li>
        </ul>
      </div>
    <% if (user) { %>
      <div class="sidebox">
        <div class="side-header">→ Submit</div>
        <div class="sidegroup">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td>Language:</td>
              <td>
                <%- partial('lang', {langs: langs, clazz: 'side-input'}) %>
              </td>
            </tr>
            <tr>
              <td>Choose file:</td>
              <td>
                <span class="uibtn upload-btn">
                  <span>选择文件</span>
                  <input type="file" id="file" name="info" data-url="/problem?pid=<%= problem.problemID %>" />
                </span>
                <span id="upload-info" class="upload-info">未选择文件</span>
            </td>
            </tr>
            <tr>
              <td></td>
              <td>
                <button id="submit" class="uibtn">
                  submit
                </button>
              </td>
            </tr>
            <tr>
              <td></td>
              <td>
                <span id="error" class="error-text">&nbsp;</span>
              </td>
            </tr>
            <tr>
              <td colspan="2">
                <div id="alert" class="alert alert-error hide">
                  <%- partial('i64_info') %>
                </div>
              </td>
            </tr>
          </table>
        </div>
      </div>
    <% } %>
      <div class="sidebox">
        <div class="side-header">→ Problem tags</div>
        <div style="padding:.5em;">
        <% if (problem.tags && problem.tags.length) { %>
          <% problem.tags.sort(function(a, b){return a-b;}).forEach(function(p){ %>
          <div class="tag-box" title="<%= PT[p] %>">
            <%= Tag[p] %>
            <% if(pvl == 1) { %><span class="del" tag="<%= p %>">×</span><% } %>
          </div>
          <% }); %>
        <% } %>
          <div style="text-align:right;clear:both;">
          <% if(pvl == 1) { %>
            <div class="hidden">Add tag:
              <select class="side-input">
                <% Tag.forEach(function(p, i){ %>
                <option value="<%= i %>" title="<%= PT[i] %>"><%= p %></option>
                <% }); %>
              </select>
            </div>
            <a href="javascript:;" id="add-tag">Add tag</a>
          <% } else { %>
            <span class="user-gray">No tag edit access</span>
          <% } %>
          </div>
        </div>
      </div>
      <% if (user && (user.name == problem.manager || user.name == 'admin')) { %>
      <div class="sidebox">
        <div class="side-header">→ Edit Problem</div>
        <ul class="edit">
          <li>Hidden:
            <select class="side-input" id="phide">
              <option value="1">Yes</option>
              <option value="" <% if (!problem.hide) { %>selected<% } %>>No</option>
            </select>
          </li>
        </ul>
      </div>
      <% } %>
    </div>
    <div class="istyle" style="padding-left:1em;margin-left:20em;border-left:1px solid #ddd">
      <h3 class="problem-header"><%= problem.title %></h3>
      <div class="prob-info">
      <% if (problem.spj == 1) { %>
        <span class="user user-red" title="答案不唯一，符合题意即可">Special Judge</span>
      <% } else if (problem.TC == 1) { %>
        <span class="user user-red" title="什么是TC模式？详情请参考FAQ">TC 模式</span>
      <% } %>
        <span class="user user-black">Time Limit: </span>
        <%= 2*problem.timeLimit %>/<%= problem.timeLimit %> MS (Java/Others)
        <span class="user user-black">Memory Limit: </span>
        <%= 2*problem.memoryLimit %>/<%= problem.memoryLimit %> KB (Java/Others)
      </div>
      <div style="padding-top:10px;" align="center">
        <%- submit %>
        <% if (!cid) { %>
        <a class="uibtn" href="/problem?pid=<%= problem.problemID+1 %>">Next Problem</a>
        <% } %>
        <% if (user) { %>
          <% if (user.addprob == 1) { %><a class="uibtn" href="/addproblem?pID=<%= problem.problemID %>">Edit Problem</a><% } %>
          <% if (user.name == 'admin'|| user.name == problem.manager) { %><a class="uibtn" href="javascript:;" id="rejudge">Rejudge</a><% } %>
        <% } %>
      </div>
  <% var S = ['Problem Description', 'Input', 'Output', 'Sample Input', 'Sample Output', 'Hint', 'Source', 'Manager'], tmp; %>
  <% if (UC) { %>
  <% tmp = '<a id="manager" href="/user/'+problem.manager+'" title="'+UT+'" class="user user-'+UC+'">'+problem.manager+'</a>'; %>
    <% if (user && user.name == 'admin') { %>
    <% tmp += '<input id="manager_input" type="text" class="input-medium" style="display:none;margin:0;padding:2px;"><a href="javascript:;" id="edit_btn" class="img_link edit" title="change" style="display:inline-block;margin-left:8px;"></a>'; %>
    <% } %>
  <% } %>
  <% var q = [problem.description, problem.input, problem.output, problem.sampleInput, problem.sampleOutput, problem.hint, problem.source, tmp]; %>
  <% for (var i in S) if (q[i]) { %>
      <h4><%= S[i] %></h4>
      <div class="accordion-inner ">
      <% if (i == 3 || i == 4) { %><pre class="sample"><%= q[i] %></pre>
      <% } else { %><%- q[i] %><% } %>
      </div>
  <% } %>
      <div align="center" style="padding-bottom: 20px;">
        <%- submit %>
      </div>
    </div>
  </div>
<% } %>
</fieldset>
<% if (user && user.name == 'admin') { %>
<script type="text/javascript">
function bindChange() {
  var $input = $('#manager_input');
  var $manager = $('#manager');
  $input.keyup(function(e){
      if (e.keyCode == 13) {
        $input.attr('disabled', true);
        $.ajax({
          type: 'POST',
          url: '/setProblemManager',
          data: { pid: pid, name: $input.val() },
          dataType: 'text',
          error: function() {
            $input.attr('disabled', false);
            ShowMessage('无法连接到服务器！');
          }
        })
        .done(function(res){
          if (!res) {
            window.location.reload(true);
            return ;
          } else if (res == '1') {
            ShowMessage('The user does NOT exist!');
          } else if (res == '3') {
            ShowMessage('系统错误！');
          }
          $input.hide();
          $manager.show();
          $edit_btn.show();
          $input.attr('disabled', false);
        });
      }
  });
  $edit_btn.click(function(){
    $edit_btn.hide();
    $manager.hide();
    $input.val($manager.text()).show();
  });
}
</script>
<% } %>